import {applyMiddleware,createStore} from 'redux';
import thunk from 'redux-thunk';
// 导入reducer
import reducers from '../reducer'

/**
 * 自定义log中间件
 * @param {*} store 
 * @returns  {function(*):Function}
 */
// 这里用到了js的函数柯里化,logger=store=>next=>action=>是函数柯里化的es6写法
const logger = store=> next=> action=>{
    if(typeof action ==='function'){
        console.log('dispatching a functiong')
    }else{
        console.log('dispatching',action)
    }
    const result =  next(action);
    console.log('nextState',store.getState());
    return result;
}


const middlewares = [
    logger,
    thunk,
];

/**
 * 创建store
 */

export default createStore(reducers,applyMiddleware(...middlewares));